package org.example.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.dao.AttractionDao;
import org.example.model.Attraction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
// 这个注解表示这是一个服务类，并且在事务中进行操作，如果出现异常，则回滚事务
@Transactional(rollbackFor = Exception.class)
public class AttractionService {
    @Autowired
    private AttractionDao attractionDao;
    public PageInfo<Attraction> getAttractionInfo(Attraction attraction) {
        PageHelper.startPage(attraction.getPageNo(), attraction.getPageSize());
        // 这里是业务逻辑代码
        List<Attraction> attractions = attractionDao.findAll(attraction);
        PageInfo<Attraction> pageInfo = new PageInfo<>(attractions);
        System.out.println(pageInfo.getPageSize());
        return pageInfo;

    }

    public Attraction getAttractionById(int id) {
        // 这里是业务逻辑代码
        Attraction attraction = attractionDao.getAttractionById(id);
        return attraction;
    }

    public List<String> getDisplayImage() {
        return attractionDao.getDisplayImage();
    }


    public String searchByWord(String keyword) {
        return attractionDao.searchByWord(keyword);
    }
}
